package com.zhao.redis;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.args.ListPosition;

import java.util.List;

//jedis操作键相关的指令
public class TestList {

    private Jedis jedis;

    @Before
    public void before() {
        jedis = new Jedis("192.168.200.120", 6379);
    }

    @After
    public void after() {
        jedis.close();
    }


    @Test
    public void testPush() {
        jedis.lpush("names", "zhangsan", "wangwu", "zhaoliu");
        jedis.rpush("names", "xiaohei");
    }

    @Test
    public void testPushx() {
        jedis.lpushx("names", "xxxxxx1");
    }

    @Test
    public void testLrange() {
        List<String> names = jedis.lrange("names", 0, -1);
        names.forEach( name -> System.out.println(name));
    }

    @Test
    public void testLpop() {
        String names = jedis.lpop("names");
        System.out.println(names);
    }

    @Test
    public void testLlen() {
        long names = jedis.llen("names");
        System.out.println(names);
    }

    @Test
    public void testLset() {
        String name = jedis.lset("names", 1, "王五2");
        System.out.println(name);
    }

    @Test
    public void testLindex() {
        String name = jedis.lindex("names", 1);
        System.out.println(name);
    }

    @Test
    public void testTrim() {
        String names = jedis.ltrim("names", 2, 3);
        System.out.println(names);
    }

    @Test
    public void testInsert() {
        long linsert = jedis.linsert("names", ListPosition.AFTER, "zhangsan", "wangwu");
        System.out.println(linsert);
    }

}
